/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package famtime.tm.kalender.model;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author Marius
 */
@Entity
@NamedQueries({
      @NamedQuery(name = Kalender.FIND_ALL, query = "select k from Kalender k order by k.name"),
    @NamedQuery(name = Kalender.FIND_BY_NAME, query = "select k from Kalender k where k.name=:name")
})
public class Kalender implements Serializable {
    private static final long serialVersionUID = 1L;
    
    public static final String FIND_BY_NAME = "Kalender.findByName";
    public static final String FIND_ALL = "Kalender.findAll";
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @OneToMany(mappedBy = "parent", cascade=CascadeType.ALL, orphanRemoval=true)
    public List<Event> events = new LinkedList<Event>();
    
    private String name;
    
    
    public Kalender() {
    }

    /**
     *
     * @param name
     */
    public Kalender(String name) {
        
        this.name = name;

    }

    public List<Event> getEvents() {
        return events;
    }

    public void setEvents(List<Event> events) {
        this.events = events;
    }

    public void addEvent(Event e){
        e.setParent(this);
        events.add(e);
    }
    
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Kalender)) {
            return false;
        }
        Kalender other = (Kalender) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "famtime.tm.kalender.Kalender[ id=" + id + " ]";
    }

    public void remove(Event e) {
        events.remove(e);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    
}
